﻿using System;
using System.Windows.Data;
using TorchView.PakViewer.Zip;
using System.Windows;
using System.Collections.ObjectModel;

namespace TorchView.PakViewer
{
    public class ZipConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
                return null;

            IZipNode node = (IZipNode)value;
            if (!node.IsDirectory)
            {
                ZipNode zip = (ZipNode)node;

                if (zip.Name.EndsWith(".dat.adm", StringComparison.CurrentCultureIgnoreCase))
                {
                    return new ObservableCollection<DataViewModel>{
                        new DataViewModel(zip.OpenFile())
                    };
                }
            }

            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    }
}
